//
//  TKCertLib.h
//  TKCertLib
//
//  Created by chensj on 14-2-26.
//  Copyright (c) 2014年 chensj. All rights reserved.
//  
/**
 使用示例：
 
 1，在程序运行期间需要load一次（程序初始化时load）：
 //[TKCertLib loadLicense:@"5FC35BF40FF544B01AFCFCB61CE52BAF7B6B2BACC45AEF1C4B288D2C63D34B2823950A3A73DF6B841C8B969F4F3221B853FCC9024842DB24"];
 
 2,创建p10
 //NSMutableString *p10 = [NSMutableString string];
 //int ret =[[TKCertLib share] createPKCS10:p10 pwd:@"123456"];
 //NSLog(@"--------------PKCS10:\n%@",p10);
 
 3,下载证书签名
 // [[TKCertLib share] importCert:@"MIIKQAYJKoZIhvcNAQcCoIIKMTCCCi0CAQExADALBgkqhkiG9w0BBwGgggoVMIIDKzCCAhOgAwIBAgIEKrH+zzANBgkqhkiG9w0BAQUFADA/MQswCQYDVQQGEwJDTjESMBAGA1UECgwJQ1NEQyBUZXN0MRwwGgYDVQQDDBNPcGVyYXRpb24gQ0EwMSBUZXN0MB4XDTE0MDMwNjA4MTYzM1oXDTE1MDMwNjA4MTYzM1owUDELMAkGA1UEBhMCQ04xEjAQBgNVBAoMCUNTREMgVGVzdDEUMBIGA1UECwwLQ3VzdG9tZXJzMDExFzAVBgNVBAMMDkNAMUAxMDAwMDMyODg1MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0XHqrwquDJa90tyjSn8YM4WYUQucp3lixqV+pfjH/Hf16C5zZ7TeSnMKMjN//bShHoLUAgofJQ9pkl7vioINiPeyz5qDtD3bgCOm2SNoEXKueyylJmYfdqjM+exzeNkgbOkWxFZ8gP/5HAW57jahlFqZ9HWdkqJfHrgpe3qAaVwIDAQABo4GhMIGeMBEGCWCGSAGG+EIBAQQEAwIFoDAJBgNVHRMEAjAAMFIGA1UdHwRLMEkwR6BFoEOkQTA/MQswCQYDVQQGEwJDTjESMBAGA1UECgwJQ1NEQyBUZXN0MQwwCgYDVQQLDANjcmwxDjAMBgNVBAMMBWNyb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z2PjpiOLQ/GAbytwm1BVsrJv/huGOVQSlX1EfeS1aedzpBp4fzPCh8c+zyTyper+uOgTfeCUv7DcEf9bromxgBTOhhMuy7w3YPErfJt15p9f+/diIXFxhv7SnJTfQ2cCAwEAAaNzMHEwEQYJYIZIAYb4QgEBBAQDAgAHMB8GA1UdIwQYMBaAFD9VeYyV9NN6zb+NU1bho96foiPJMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgH+MB0GA1UdDgQWBBQ/VXmMlfTTes2/jVNW4aPen6IjyTANBgkqhkiG9w0BAQUFAAOCAQEAeWih0VwaBz5pcjRcQii7uW3KdIzktBoqmXyRGX6MCrwH+ILVt6DxSCOnrm55eqv6YPHB24YU/G77j3XmgD/xqFTM6IkPafDyPxtBmUTfiPETsaIHErLvuXNsGqPtS0teJV5qeFkEHQLcBwHr0bNDkxJNERNBndcX7ZoHZRznV291SzcpaGIYJjZfb/bNwUKBFa7SWz6/pdC4A6iRInHgerx/Glwf7xin1BzQarqnEhEToIfpkXJxsyOITBwYZNfcDVjGdMM1hq9UVjVTn26t0LtG6xP/2pQvqHQjVsDiojJiuSjUtGppDW7FKM0z9qegiSBplolI4+9zEmsKXDH1bzEA"];
 
 // NSString *ret =[[TKCertLib share] sign:@"thinkive1000" target:nil signType:TK_SIGN_TYPE_DETACH];
 // NSLog(@"----------ret-----------\n%@",ret);
 
 */
#import <Foundation/Foundation.h>

#define TK_algorithm_MD5 @"md5"
#define TK_algorithm_SHA1 @"sha1"

#define TK_SIGN_TYPE_ATTACH 1  //暂不支持
#define TK_SIGN_TYPE_DETACH 2
#define TK_SIGN_TYPE_RAW 3   //暂不支持

///error def
#define ERR_CERT_UNDEF 99

#define ERR_CREATEP10_OK 0
#define ERR_CREATEP10_GENERATE 1
#define ERR_CREATEP10_SAVE 2
#define ERR_CREATEP10_READ 3

#define ERR_IMPORT_OK 0
#define ERR_IMPORT_PARSE 1
#define ERR_IMPORT_VERIFY 2

@interface TKCertLib : NSObject

+(void)loadLicense:(NSString*)license;

+(TKCertLib*)share;

/**
 生成P10
 return ERR_CREATEP10_XX，p10为pkcs10.
 */
-(int)createPKCS10:(NSMutableString *)p10 pwd:(NSString *)pwd userID:(NSString *)userid;

/**
 安装证书
 return ERR_IMPORT_XX
 */
-(int)importCert:(NSString*)content userID:(NSString*)userid;

/**
 签名
 return 空则签名失败，否则返回签名后base64信息
 */
-(NSString*)sign:(NSString*)sourceStr signType:(int)sType userID:(NSString*)userid;

/**
 *  @Author 刘宝, 2015-07-17 14:07:41
 *
 *  删除证书
 *
 *  @param userid
 */
-(void)clearAllCer :(NSString *)userid;

@end
